package controller;

import java.awt.Point;
import java.io.PrintWriter;

public class Logger {

	// members
	private static final String FILE_NAME = "src/logFile.txt";
	
	private PrintWriter writer;

	// private methods
	public void writeToFile(String type, String log) throws Exception {

		// write log
		writer.println(type + log);
		writer.flush();
	}

	public void close() {
		writer.close();
	}

	// public methods

	// Ctor
	public Logger() throws Exception {

		// open file
		writer = new PrintWriter(FILE_NAME);
	}

	// write that a move was made
	public void writeMove(Point src, Point dest) {

		// write move to file
		try {
			writeToFile("m ", src.x + "," + src.y + " to " + dest.x + ","
					+ dest.y);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// write that adds a creature
	public void writeCreatur(Point position) {

		// write creature's position
		try {
			writeToFile("c ", position.x + "," + position.y);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void writeCollide(Point position) {

		// write collision position
		try {
			writeToFile("l ", position.x + "," + position.y);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// write that a piece was destroyed by a creature
	public void writePieceDestroyed(Point position) {

		// write piece's position
		try {
			writeToFile("d ", position.x + "," + position.y);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	// write random's seed
	public void writeSeed(long seed) {
		
		// write seed
		try {
			writeToFile("seed: ", seed+"");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void writeMoveHuman(Point src, Point dest) {
		
		// write move
		try {
			writeToFile("human: ", src.x + "," + src.y + " to " + dest.x + ","
					+ dest.y);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void writeMoveComputer(Point src, Point dest) {
		
		// write move
		try {
			writeToFile("computer: ", src.x + "," + src.y + " to " + dest.x + ","
					+ dest.y);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}